﻿namespace jzgl.Controller
{
    using jzgl.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    public class BudgetDetailsDB
    {
        private SqlConnection conn = null;
        private ConnDB conndb = new ConnDB();
        private DataTable table = null;

        public BudgetDetailsDB()
        {
            this.conn = this.conndb.GetConnString();
        }

        public int Add_BudgetDetails(BudgetDetails b)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = string.Concat(new object[] { 
                        "insert into BudgetDetails (BudDetKey,BudInfoNodeId,BudDetName,BudDetUnit,BudDetPrice,BudDetNum,BudDetSum,BudDetTech,BudDetRemark)  values('", b.BudDetKey, "','", b.BudInfoNodeId, "','", b._BudDetName, "','", b._BudDetUnit, "','", b._BudDetPrice, "','", b._BudDetNum, "','", b._BudDetSum, "','", b._BudDetTech, 
                        "','", b._BudDetRemark, "')"
                     });
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message + "99999999999999999999999");
                }
            }
            finally
            {
            }
            return num;
        }

        public int Delete_BudgetDetails(BudgetDetails b)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "delete from BudgetDetails where BudDetId='" + b._BudDetId + "'";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public int Delete_BudgetDetails(string BudDetKey)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "delete from BudgetDetails where BudDetKey='" + BudDetKey + "'";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public DataTable Show_BudgetDetails()
        {
            try
            {
                try
                {
                    string sql = "select * from BudgetDetails";
                    this.table = this.conndb.FillDataTable(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return this.table;
        }

        public void Show_BudgetDetails(DataGridView dgv)
        {
            try
            {
                try
                {
                    string sqlstr = "select * from BudgetList";
                    this.conndb.dgvDataBind(dgv, sqlstr);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
        }

        public DataTable Show_BudgetDetailsYBudInfo_Id(string infoId)
        {
            try
            {
                try
                {
                    string sql = "select * from BudgetDetails where BudInfoNodeId='" + infoId + "'";
                    this.table = this.conndb.FillDataTable(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return this.table;
        }

        public DataTable Show_BudgetDetailsYBudInfo_Id(string infoId, string listId)
        {
            try
            {
                try
                {
                    string sql = "select * from BudgetDetails where BudInfoNodeId='" + infoId + "' and  BudDetKey='" + listId + "'";
                    this.table = this.conndb.FillDataTable(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return this.table;
        }

        public int Update_BudgetDetails_Price(BudgetDetails b)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = string.Concat(new object[] { "update BudgetDetails set BudNum='", b._BudDetNum, "',BudDetSum='", b._BudDetSum, "'   where BudDetID='", b._BudDetId, "' and  BudInfoId='", b._BudInfoId, "'" });
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }
    }
}

